#include "stdafx.h"

HSPlayer* HSPlayer::sPlayer = NULL;

HSPlayer& HSPlayer::GetInstance()
{
	if ( !sPlayer )
	{
		sPlayer = new HSPlayer();
	}

	return *sPlayer;
}

HSPlayer::HSPlayer()
{
	bActive = false;
}

HSPlayer::~HSPlayer()
{

}

bool HSPlayer::Load( const std::string& sName )
{
	SetSize( MathUtil::PixelsToWorldUnits( 64.0f ), MathUtil::PixelsToWorldUnits( 64.0f ) );
	SetSprite( "Resources/Images/hero.png" );
	SetPosition( 0.0f, 0.0f );
	return true;
}

void HSPlayer::Update( float dt )
{
	if ( !bActive )
	{
		return;
	}

	Actor::Update( dt );
	theWorld.UpdateLayer( this, -(int)((MathUtil::WorldUnitsToPixels( _position.Y ) + 1.0f) / 32.0f) );
}

void HSPlayer::GoTo( Vec2i screenCoordinates )
{
	Vector2 worldCoordinates = MathUtil::ScreenToWorld( screenCoordinates );
	float fDistance = Vector2::Distance( GetPosition(), worldCoordinates );
	MoveTo( worldCoordinates, fDistance / 5.0f, false, "" );
}

void HSPlayer::Activate()
{
	if ( bActive )
	{
		return;
	}

	theWorld.Add( this );
	theCamera.LockTo( this, true, true, false );
	bActive = true;
}

void HSPlayer::Deactivate()
{
	if ( !bActive )
	{
		return;
	}

	theWorld.Remove( this );
	bActive = false;
}
